/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentRanking.java
 *
 * Created on 11-may-2010, 12:08:40
 */

package Blackjack;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Label;
import java.awt.Toolkit;
import javax.swing.JFrame;
import prop.Posicion;

/**
 *
 * @author Red
 */
public class VentRanking extends javax.swing.JFrame {


    /** Creates new form VentRanking */
    private Label vLabelNombre[], vLabelFecha[], vLabelPuntos[];
    private DriverRanking DR;

    /** Creates new form VentanaRanking */
    public VentRanking(DriverRanking dr) {
        initComponents();
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension screenSize = tk.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        this.setLocation((screenWidth - this.getWidth())/2, (screenHeight - this.getHeight())/2);
        DR = dr;

        Label tituloNombre = new Label();
        tituloNombre.setBounds(30, 20, 150, 20);
        tituloNombre.setText("Nombre");
        tituloNombre.setFont(new Font(null, Font.BOLD, 15));
        this.add(tituloNombre);

        Label tituloFecha = new Label();
        tituloFecha.setBounds(190, 20, 150, 20);
        tituloFecha.setText("Fecha");
        tituloFecha.setFont(new Font(null, Font.BOLD, 15));
        this.add(tituloFecha);

        Label tituloPuntos = new Label();
        tituloPuntos.setBounds(350, 20, 60, 20);
        tituloPuntos.setText("Puntos");
        tituloPuntos.setFont(new Font(null, Font.BOLD, 15));
        this.add(tituloPuntos);

        this.setResizable(false);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setVisible(true);

    }

    public void escribeRanking(Posicion[] vect) {
        if (vLabelNombre != null) {
            for (int i = 0; i < vLabelNombre.length; ++i) {
                this.remove(vLabelNombre[i]);
                this.remove(vLabelFecha[i]);
                this.remove(vLabelPuntos[i]);
            }
        }
        int n = vect.length;
        vLabelNombre = new Label[n];
        vLabelFecha = new Label[n];
        vLabelPuntos = new Label[n];
        for (int i = 0; i < n; ++i) {
            vLabelNombre[i] = new Label();
            vLabelFecha[i] = new Label();
            vLabelPuntos[i] = new Label();

            vLabelNombre[i].setBounds(30, 50 + 25*i, 150, 20);
            vLabelFecha[i].setBounds(190, 50 + 25*i, 150, 20);
            vLabelPuntos[i].setBounds(350, 50 + 25*i, 60, 20);

            vLabelNombre[i].setText(vect[i].nombre);
            vLabelFecha[i].setText(vect[i].fecha);
            vLabelPuntos[i].setText(String.valueOf(vect[i].puntuacion));

            this.add(vLabelNombre[i]);
            this.add(vLabelFecha[i]);
            this.add(vLabelPuntos[i]);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ranking");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jButton1.setText("Volver");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Resetear");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(235, Short.MAX_VALUE)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(434, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        DR.cierraRanking();
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        DR.abrirResetRanking();
        this.setEnabled(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        DR.cierraRanking();
        this.dispose();
    }//GEN-LAST:event_formWindowClosing

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentRanking().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    // End of variables declaration//GEN-END:variables

}
